package it.traveldream.entities;

import it.traveldream.dto.ExcursionDTO;
import it.traveldream.utils.CalendarUtils.WeekDay;

import java.math.BigDecimal;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: Excursion
 * NB: FUNC() function is MySQL / Eclipselink dependent
 *
 */
@Entity
@Table(name = "Excursion")
@DiscriminatorValue(ProductType.EXCURSION)

@NamedQueries({
	@NamedQuery(
			name = "getAllExcursionsInLocation",
			query = "SELECT e FROM Excursion e WHERE e.location = :location"
			),
	@NamedQuery(
			name = "getAlternativeExcursionInLocation",
			query = "SELECT e FROM Excursion e WHERE e.location = :location AND "
					+ "e.productId NOT IN :idList"
			),
	@NamedQuery(
			name = "getAvailableExcursionBetweenDates",
			query = "SELECT e FROM Excursion e "
					+ "WHERE e.location = :location AND "
					+ "e.weekDay BETWEEN FUNC('WEEKDAY', :since) AND FUNC('WEEKDAY', :until)"
			)		
})

public class Excursion extends Product {

	private Integer duration;
	private BigDecimal price;
	private WeekDay weekDay;
	
	private static final long serialVersionUID = 1L;

	public Excursion() {
		super();
	}   
	public Excursion(String name, Location l){
		super();
		this.name = name;
		this.location = l;
	}
	
	public Integer getDuration() {
		return this.duration;
		
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}   
	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	public WeekDay getWeekDay() {
		return this.weekDay;
	}
	public void setWeekDay(WeekDay weekDay) {
		this.weekDay = weekDay;
	}
   
	@Override
	public ExcursionDTO toDTO(){
		ExcursionDTO dto = new ExcursionDTO();
		dto.setProductId(this.productId);
		dto.setName(this.name);
		dto.setLocation(this.location.toDTO());
		
		dto.setDuration(this.duration);
		dto.setPrice(this.price);
		dto.setWeekDay(this.weekDay);
		
		return dto;
	}
}
